package com.itheima.advice;

import com.github.pagehelper.PageHelper;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author itheima
 * @since 2021-10-24
 */
@Component
@Aspect
public class AopAdvice {

    /**
     * 切入点 PointCut
     */
    @Pointcut("execution(public * com.itheima.service.EmployeeService.*(java.lang.Integer, java.lang.Integer))")
    private void pt() {

    }

    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        // 获取被拦截方法的实参
        Object[] args = pjp.getArgs();

        Integer page = (Integer) args[0];
        Integer pageSize = (Integer) args[1];

        // 调用分页方法
        PageHelper.startPage(page, pageSize);

        // 调用被拦截方法
        return pjp.proceed(args);
    }
}
